package com.spzx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.core.utils.StringUtils;
import com.spzx.user.domain.Region;
import com.spzx.user.domain.UserAddress;
import com.spzx.user.domain.UserInfo;
import com.spzx.user.service.RegionService;
import com.spzx.user.mapper.RegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author DELL
* @description 针对表【region(地区信息表)】的数据库操作Service实现
* @createDate 2024-10-23 21:47:01
*/
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region>
    implements RegionService{

    @Autowired
    private RegionMapper regionMapper;

    //根据code获取region信息
//    @Override
//    public String getlist1(String code) {
//        if(StringUtils.isEmpty(code)){
//            return "";
//        }
//        Region region = regionMapper.selectOne(new LambdaQueryWrapper<Region>().eq(Region::getParentCode, code).select(Region::getName));
//        if(region!=null){
//            String name = region.getName();
//            return name;
//        }
//
//        return "";
//    }


    //根据code获取region信息
    @Override
    public List<Region> getlist(String code) {
       List<Region>  regionList = regionMapper.selectList(new LambdaQueryWrapper<Region>().eq(Region::getParentCode,code));
        return regionList;
    }


    @Override
    public String getNameByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return "";
        }
        Region region = regionMapper.selectOne(new LambdaQueryWrapper<Region>().eq(Region::getCode,code).select(Region::getName));
        if(null != region) {
            return region.getName();
        }
        return "";
    }
}




